/*
 * @Author: TC
 * @Date: 2025-06-19 16:40:35
 * @Last Modified by: TC
 * @Last Modified time: 2025-06-20 14:40:55
 */

import { EntityBase } from "../EntityBase";
import { SkillItem } from "../Skill/SkillItem";

/**
 * 实体技能
 */
export class EntitySkill {
    private _entity: EntityBase = null;

    private _mapSkill: Map<number, SkillItem> = new Map();
    public get entity(): EntityBase {
        return this._entity;
    }

    constructor(entity: EntityBase) {
        this._entity = entity;
        this.loadDefSkill();
    }

    /**
     * 装载技能
     * @param cfgId
     * @param slot
     */
    public loadSkill(cfgId: number, slot: number): void {
        if (this._mapSkill.has(slot)) {
            this.unLoadSkill(slot);
        }
        const skill = new SkillItem(this, cfgId);
        this._mapSkill.set(slot, skill);
    }

    /**
     * 卸载某一插槽的技能
     */
    public unLoadSkill(slot: number): void {
        this._mapSkill.delete(slot);
    }

    /**
     * 使用某一插槽的技能
     * @param slot
     */
    public useSkill(slot: number): void {
        const skill = this._mapSkill.get(slot);
        if (skill) {
            skill.use();
        }
    }

    /**
     * 装载默认技能
     */
    public loadDefSkill(): void {
        this.loadSkill(1, 0);
    }

    public tick(dt: number): void {
        this._mapSkill.forEach((skill) => {
            skill.tick(dt);
        });
    }
}
